# Copyright (C) 2017 Michael Reed <michael@michaelreed.io>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

MD_MAIN != find -L . -name '*.md' -and ! -path '*/article/*'
HTML_MAIN = $(MD_MAIN:.md=.html)

MD_NEWS != cat MANIFEST
HTML_NEWS = $(MD_NEWS:.md=.html)
HTML_BARE_NEWS = $(MD_NEWS:.md=.bare.html)


# index.html implies the building of $(HTML_BARE_NEWS).
all: $(HTML_MAIN) $(HTML_NEWS) index.html

.SUFFIXES: .md .html .bare.html
.md.html:
	./publish.sh $<

.md.bare.html:
	pandoc $(<) > $(<:.md=.bare.html)

# Unlike all the other markdown files, index.md does not exist at first:
# it must be generated by index.sh. Also note that index.sh generates the RSS
# feed, which requires the bare HTML versions of all news items.
index.md: $(HTML_BARE_NEWS)
	./index.sh

clean:
	rm -f	$(HTML_MAIN) $(HTML_NEWS) $(HTML_BARE_NEWS) \
		index.md index.html index.bare.html \
		feed.xml

.PHONY: clean
